<?php
/**
 * Minhlog Domain_Table 抽象类
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 *
 * @category   Domain
 * @package    Domain_Table
 * @copyright  Copyright (c) 2009-2010 Minh.Shu@gmail.com
 * @license    New BSD License
 * @author     Minh.Shu
 * @version    $Id: Abstract.php 2 2010-01-17 13:49:08Z Minh.Shu $
 *
 */

abstract class Domain_Table_Abstract extends Zend_Db_Table_Abstract
{
    /**
     * 初始化数据库对象
     * @access protected
     * @return object
     */
    protected function _setup ()
    {
        if(null !== $this->_db) {
            return $this->_db;
        } elseif(null === $this->_db && method_exists($this, '_dbConnect')) {
            $this->_dbConnect();
        } else {
            throw new Exception('建立数据库链接失败!');
        }
    }

    /**
     * 建立数据库链接
     * @access private
     * @return object
     */
    final private function _dbConnect ()
    {
        $bootstrap = Zend_Controller_Front::getInstance()->getParam('bootstrap');
        $resource = $bootstrap->getPluginResource('db');
        $this->_db = $resource->getDbAdapter();
        return $this;
    }
}